<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    div {
      height: 500px;
      width: 500px;
      position: relative;
    }

    img {
      /* 通过设置定位让图片重叠在一起 */
      position: absolute;
      width: 100%;
      height: 100%;
    }
  </style>
</head>

<body>
  <div>
    <img src="./img/1.jpg" alt="">
    <img src="./img/2.jpg" alt="">
    <img src="./img/3.jpg" alt="">
    <img src="./img/4.jpg" alt="">
  </div>
  <script>
    //实现轮播图的方式有三种
    //1、通过display属性设置图片的显隐
    //2、通过opacity透明度来设置图片的显隐
    //3、通过控制距离实现图片的显示隐藏
    let img = document.getElementsByTagName("image")
    let i = img.length-1
    setInterval(function () {
      img[i].style.opacity = 0
      i--
      if (i == 0) {
        i = img.length-1
        for (j = 0; j < img.length; j++) {
          img[j].style.opacity = 1
        }
      }
    }, 2000)
  </script>
</body>

</html>